package cvi.com.reader.base;

import android.content.Context;
import android.media.MediaPlayer;

/**
 * Created by 梅涛 on 2020/8/6.
 * 音乐播放器单例模式
 */

public class MyPlayer extends MediaPlayer {
    private static Context mContext;
    private static Object INSTANCE_LOCK = new Object();
    private static MyPlayer myPlayer = null;

    public static MyPlayer getInstance(Context context) {
        synchronized (INSTANCE_LOCK) {
            if (myPlayer == null) {
                myPlayer = new MyPlayer();
            }
        }
        mContext = context;
        return myPlayer;
    }

    public void stop() {
        if (myPlayer != null) {
            myPlayer.stop();
            myPlayer.release();
        }
    }
}
